﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services;
using Simple.Services.System.DeviceManagement;
using Simple.Services.System.DeviceManagement.Models;
using Simple.Services.System.MorningCheck;
using Simple.Services.System.MorningCheck.Models;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 音响设备管理
    /// </summary>
    [Route("api/Device/[action]")]
    [ApiController]
    [Authorize]
    public class DeviceController : ControllerBase
    {
        private readonly DeviceService _deviceService;
        public DeviceController(DeviceService deviceService)
        {
            _deviceService = deviceService;
        }

        /// <summary>
        /// 设备记录列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetPage([FromQuery] DevicePageQueryModel model)
        {
            var data = await _deviceService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 同步数据设备列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetSyncDataList()
        {
            var data = await _deviceService.GetSyncDataList();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 添加设备
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromBody] DeviceCreateOrUpdateModel model)
        {
            await _deviceService.AddAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 编辑设备
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromBody] DeviceCreateOrUpdateModel model)
        {
            await _deviceService.UpdateAsync(model);
            return AppResult.Status200OK("修改成功");
        }

        /// <summary>
        /// 删除设备
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] IdInputModel model)
        {
            await _deviceService.DeleteAsync(model.Id);
            return AppResult.Status200OK("删除成功");
        }

    }
}
